//以下为修改jQuery Validation插件兼容Bootstrap的方法，没有直接写在插件中是为了便于插件升级
        $.validator.setDefaults({
            highlight: function (element) {
                $(element).closest('#form-group').removeClass('has-success').addClass('has-error');
            },
            success: function (element) {
                element.closest('#form-group').removeClass('has-error').addClass('has-success');
            },
            errorElement: "span",
            errorPlacement: function (error, element) {
                if (element.is(":radio") || element.is(":checkbox")) {
                    error.appendTo(element.parent().parent().parent());
                } else {
                	error = $(error).css('margin-top','-10px');
                	error = $(error).css('margin-left','80px');
                	element.parent().parent().next().before(error);
                }
            },
            errorClass: "help-block m-b-none",
            validClass: "help-block m-b-none"


        });
      

        //以下为官方示例
        $().ready(function () {
            // validate the comment form when it is submitted
            $("#commentForm").validate();

            // validate signup form on keyup and submit
            var icon = "<i class='fa fa-times-circle'></i> ";
            $("#zhuce").validate({
                rules: {
                    user_account: "required",
                    user_name: "required",
                    user_tel: {
                        required: true,
                        digits:true,
                        minlength: 11,
                        maxlength:11
                    },
                    user_idcard: {
                        required: true,
                        minlength: 18,
                        maxlength:18
                    },
                    user_ems: {
                        required: true,
                        digits:true,
                        minlength: 6,
                        maxlength: 6
                    },
                    user_card: {
                        required: true,
                        digits:true,
                        minlength: 16,
                        maxlength: 19
                    },
                    user_pwd: {
                    	required: true,
                        minlength: 3,
                        maxlength: 16
                    },
                    user_tpwd: {
                    	required: true,
                    	digits:true,
                        minlength: 6,
                        maxlength: 6
                    },
                    user_address: {
                    	required: true
                    },
                    user_time: {
                    	required: true
                    }
                    
                },
                messages: {
                    user_account: icon + "请输入你的账号",
                    user_name: icon + "请输入您的名字",
                    user_tel: {
                        required: icon + "请输入您的电话号码",
                        minlength: icon + "请输入位数正确的电话号码",
                        maxlength: icon + "请输入位数正确的电话号码"
                    },
                    user_idcard: {
                        required: icon + "请输入您的二代身份证号码",
                        minlength: icon + "请输入合法的身份证号码",
                        maxlength: icon + "请输入合法的身份证号码"
                    },
                    user_ems: {
                        required: icon + "请输入邮政编码",
                        minlength: icon + "请输入正确的邮政编码",
                        maxlength: icon + "请输入正确的邮政编码"
                    },
                    user_card: {
                    	required: icon + "请输入开户银行卡号",
                        minlength: icon + "请输入正确的银行卡号",
                        maxlength: icon + "请输入正确的银行卡号"
                    },
                    user_pwd: {
                        required: icon + "请输入您的密码",
                        minlength: icon + "密码至少3位"
                    },
                    user_tpwd: {
                    	required: icon + "请输入您的二级密码",
                        minlength: icon + "请输入正确的6位密码",
                        maxlength: icon + "请输入正确的6位密码"
                    },
                    user_address: {
                    	required: icon + "请输入收货地址"
                    },
                    user_time: {
                    	required: icon + "请选择创建日期"
                    }
                    
                }
            });

            // propose username by combining first- and lastname
            $("#username").focus(function () {
                var firstname = $("#firstname").val();
                var lastname = $("#lastname").val();
                if (firstname && lastname && !this.value) {
                    this.value = firstname + "." + lastname;
                }
            });
        });
